<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="formEntRelationAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="add">{{$ti18('rxList.newBtn','新建')}}
                        </rx-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0"
                                             alias="formEntRelationEdit" :butn-icon="'edit'"
                                             :butn-type="'primary'" :show-no-right="false" @click="editOne">
                                    <a-icon type="edit"/>
                                    {{$ti18('rxList.editBtn','编辑')}}
                                </a-menu-item>
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0"
                                             alias="formEntRelationDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                             :show-no-right="false" @click="delByIds(selectedRowKeys)">
                                    <a-icon type="delete"/>
                                    {{$ti18('rxList.delBtn','删除')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.entityName','实体名称')">
                            <a-input :placeholder="i18n('form.entityName','实体名称','input')" v-model="queryParam.Q_ENT_NAME__S_LK"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formEntRelation/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    bordered
                    @selectChange="onSelectChange"
                >
                    <span slot="appId" slot-scope="{ text, record }">
                        {{allApps[text]?$i18(allApps[text].appName,'应用名称'):$ti18('rxList.noAppName','无')}}
                    </span>
                    <span slot="exportApp">
                         {{ exportI18n('export.isExport','导出') }}
                        <export-app/>
                    </span>
                    <span slot="isExport" slot-scope="{ text, record }">
                        <a-tag :color="text == 1 ? 'green' : 'red'">
                            <span>{{ text == 1 ? exportI18n('export.yes','是') : exportI18n('export.no','否') }}</span>
                        </a-tag>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span  @click.stop="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                        <span  @click.stop="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                        <span @click="setExport(record,exportConf)">{{record.isExport == 1 ? exportI18n('export.noExport','不导出') : exportI18n('export.exported','导出')}}</span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import FormEntRelationApi from '@/api/form/core/formEntRelation'
import FormEntRelationEdit from './FormEntRelationEdit'
import {BaseList, RxFit, RxGrid} from "@lowcode/jpaas-common-lib";
import {mapState} from "vuex";
import exportApp from "@/views/modules/share/exportApp";
import switchExport from "@/utils/switchExport";

export default {
    name: 'FormEntRelationList',
    mixins: [BaseList,switchExport],
    components: {
        RxFit,
        exportApp
    },
    computed: {
        ...mapState({
            //所属应用
            allApps: state => state.appSetting ? state.appSetting.allApps : {}
        }),
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 60,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.entityName','实体名称'), dataIndex: 'entName', width: 100},
                {title: this.i18n('form.tableName','表名'), dataIndex: 'tableName', width: 100},
                {
                    dataIndex: 'isExport',
                    slots: { title: 'exportApp' },
                    width: 100,
                    scopedSlots: {customRender: 'isExport'}
                },
                {title: this.i18n('form.application','所属应用'), dataIndex: 'appId', width: 100, sortField: 'APP_ID_',scopedSlots: {customRender: 'appId'}},
                {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ],
            component: FormEntRelationEdit,
            comment: this.i18n('list.dataDelete','数据关联删除约束'),
            max:true,
            // widthHeight: ['1100px', '650px'],
            fitSearch: false,
            /**
             * 导出配置
             */
            exportConf:{
                Api:FormEntRelationApi,
                id:"id"
            }
        }
    },
    created() {
        this.needFilterAppId();
        this.columns=this.removeAppColumn(this.curApp.appId,this.columns)
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "formEntRelation", key);
        },
        exportI18n(name,text,key){
            return this.$ti18(name,text,"appExport",key);
        },
        delById(ids) {
            return FormEntRelationApi.del({ids: ids.join(',')});
        },

    }
}
</script>
<style scoped>

</style>

